<%@page import="java.text.ParseException"%>
<%@page import="java.text.ParseException"%>
<%@page import="com.sun.java.swing.plaf.windows.WindowsBorders.DashedBorder"%>
<%@page import="comits.web.client.servlets.DateUtil"%>
<%@page import="javax.print.DocFlavor.STRING"%>
<%@page import="java.text.DateFormat"%>
<%@page import="java.text.SimpleDateFormat"%>

<%@page import="java.util.Calendar"%>
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="d" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Document sans titre</title>
        <link href="styles.css" rel="stylesheet" type="text/css"/>
    </head>
    <body >
        <% java.util.Date date = (java.util.Date) request.getAttribute("date");
            if (date == null) {
                date = new java.util.Date();
            }
            java.sql.Date dateDebut = new Date(DateUtil.mondayOfWeek(date).getTime());
            java.sql.Date dateFin = new Date(DateUtil.saturdayOfWeek(date).getTime());
            java.sql.Date lundi = new Date((DateUtil.mondayOfWeek(date).getTime()));
            java.sql.Date mardi = new Date((DateUtil.mardi(date).getTime()));
            java.sql.Date mercredi = new Date((DateUtil.mercredi(date).getTime()));
            java.sql.Date jeudi = new Date((DateUtil.jeudi(date).getTime()));
            java.sql.Date vendredi = new Date((DateUtil.vendredi(date).getTime()));
            java.sql.Date samedi = new Date((DateUtil.samedi(date).getTime()));
            int numeroSemaine = DateUtil.numberOfWeek(date);
        %>
        <%
            String lundi1 = dateDebut.toString();
            String date2 = dateFin.toString();
            String mardi1 = mardi.toString();
            String mercredi1 = mercredi.toString();
            String jeudi1 = jeudi.toString();
            String vendredi1 = vendredi.toString();
            String samedi1 = samedi.toString();

        %>

        <sql:query var = "queryresults" dataSource = "jdbc/WebTest1" > 
            <%-- select distinct *  from comits_base.commande where WEEK(DateRecepPrevue)= <%=week%>   --%>
            select * from comits_base.commande where  DateRecepPrevue between '<%=dateDebut%>' and '<%=dateFin%>'
        </sql:query> 
        <div class="text" align="center">
            <p>
                <% Calendar cal = Calendar.getInstance();
                    // int annee = cal.get(Calendar.YEAR);
                    // int mois = cal.get(Calendar.MONTH) + 1;
                    // int jour = cal.get(Calendar.DAY_OF_MONTH);
                    // int f = cal.get(Calendar.WEEK_OF_YEAR);
                    cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
                    //   out.println("Planning des approvisionnements de la semaine  - "+numeroSemaine);
                    DateFormat df = new SimpleDateFormat(" dd/MM/yyyy");
                    //   out.println(" du  " + df.format(dateDebut));
                    cal.add(Calendar.DATE, 5);
                    //   out.println(" au " + df.format(dateFin));

                %>  
                <h1>Planning des approvisionnements de la semaine  -  <%=numeroSemaine%></h1>
                <h1> Du  <%=df.format(dateDebut)%>  Au <%=df.format(dateFin)%></h1>

            </p>
        </div>     
       
        <div id="contener" >
            <div id="precedent">
                <div>              
                    <form   action="PlanningServlet" method="get" >
                        <input  type="submit" name="action" class="button"  value="Precedent" />  
                    </form>
                </div>
            </div>
            <div id="suivant"   >
                <div>
                    <form action="PlanningServlet" method="get" >
                        <input   type="submit" name="action" class="button"  value="Suivant" />  
                    </form>
                </div>
            </div>
            <div id="pannel_1">
                <c:forEach var="row" items="${queryresults.rows}" varStatus="status" >

                    <c:set var="datejour" value="<%=lundi1%>"/>
                    <c:if test="${row.DateRecepPrevue ==datejour}" >
                        <div >  
                            <form action="PlanningServlet" method="get">
                                <input type="hidden" name="action"  class="boutton" value="${row.NUMCMD} ${datejour} ${row.EXPEDITEUR} ${row.NUMEXP} ${row.DESTINATAIRE} ${row.NUMDEST}"/>
                                <input  type="submit"  name="action1" class="button"  value="${row.EXPEDITEUR}-${row.NUMEXP}-->${row.DESTINATAIRE}-${row.NUMDEST}" />  
                            </form>
                        </div>
                        <br/>
                    </c:if>
                </c:forEach>
            </div>

            <div id="pannel_2"> 
                <c:forEach var="row" items="${queryresults.rows}" varStatus="status">
                    <c:set var="datejour" value="<%=mardi1%>"/>
                    <c:if test="${row.DateRecepPrevue==datejour}">
                        <div > 
                            <form action="PlanningServlet" method="get">
                                <input type="hidden" name="action"  class="boutton" value="${row.NUMCMD} ${datejour} ${row.EXPEDITEUR} ${row.NUMEXP} ${row.DESTINATAIRE} ${row.NUMDEST}"/>
                                <input  type="submit"  name="action1" class="button"  value="${row.EXPEDITEUR}-${row.NUMEXP}-->${row.DESTINATAIRE}-${row.NUMDEST}" />  
                            </form>
                        </div>
                        <br/>
                    </c:if>
                </c:forEach>
            </div>

            <div id="pannel_3">
                <c:forEach var="row" items="${queryresults.rows}" varStatus="status">
                    <c:set var="datejour" value="<%=mercredi1%>"/>
                    <c:if test="${row.DateRecepPrevue==datejour}">
                        <div > 
                            <form action="PlanningServlet" method="get">
                                <input type="hidden" name="action"  class="boutton" value="${row.NUMCMD} ${datejour} ${row.EXPEDITEUR} ${row.NUMEXP} ${row.DESTINATAIRE} ${row.NUMDEST}"/>
                                <input  type="submit"  name="action1" class="button"  value="${row.EXPEDITEUR}-${row.NUMEXP}-->${row.DESTINATAIRE}-${row.NUMDEST}" />  
                            </form>
                        </div>
                        <br/>
                    </c:if>
                </c:forEach>
            </div>                  

            <div id="pannel_4" >
                <c:forEach var="row" items="${queryresults.rows}" varStatus="status">
                    <c:set var="datejour" value="<%=jeudi1%>"/>
                    <c:if test="${row.DateRecepPrevue==datejour}">
                        <div > 
                            <form action="PlanningServlet" method="get">
                                <input type="hidden" name="action"  class="boutton" value="${row.NUMCMD} ${datejour} ${row.EXPEDITEUR} ${row.NUMEXP} ${row.DESTINATAIRE} ${row.NUMDEST}"/>
                                <input  type="submit"  name="action1" class="button"  value="${row.EXPEDITEUR}-${row.NUMEXP}-->${row.DESTINATAIRE}-${row.NUMDEST}" />  
                            </form>
                        </div>
                        <br/>
                    </c:if>    
                </c:forEach>
            </div>

            <div id="pannel_5" >   
                <c:forEach var="row" items="${queryresults.rows}" varStatus="status">
                    <c:set var="datejour" value="<%=vendredi1%>"/>
                    <c:if test="${row.DateRecepPrevue==datejour}">             
                        <div > 
                            <form action="PlanningServlet" method="get">
                                <input type="hidden" name="action"  class="boutton" value="${row.NUMCMD} ${datejour} ${row.EXPEDITEUR} ${row.NUMEXP} ${row.DESTINATAIRE} ${row.NUMDEST}"/>
                                <input  type="submit"  name="action1" class="button"  value="${row.EXPEDITEUR}-${row.NUMEXP}-->${row.DESTINATAIRE}-${row.NUMDEST}" />  
                            </form>
                        </div>
                        <br/>
                    </c:if>
                </c:forEach>
            </div>

            <div id="pannel_6" >   
                <c:forEach var="row" items="${queryresults.rows}" varStatus="status">
                    <c:set var="datejour" value="<%=samedi1%>"/>
                    <c:if test="${row.DateRecepPrevue==datejour}"> 
                        <div > 
                            <form action="PlanningServlet" method="get">
                                <input type="hidden" name="action"  class="boutton" value="${row.NUMCMD} ${datejour} ${row.EXPEDITEUR} ${row.NUMEXP} ${row.DESTINATAIRE} ${row.NUMDEST}"/>
                                <input  type="submit"  name="action1" class="button"  value="${row.EXPEDITEUR}-${row.NUMEXP}-->${row.DESTINATAIRE}-${row.NUMDEST}" />  
                            </form>
                        </div>
                        <br/>
                    </c:if>
                </c:forEach>
            </div>
            
            
        </div>
        <div id="quitter" align="right">
                <div>              
                    <form   action="PlanningServlet" method="get" >
                        <input  type="submit" name="action" class="button"  value="Quitter" />  
                    </form>
                </div>
            </div>        
       
    </body>
</html>
